//
//  YCExamStrategyCell.m
//  YCSchool
//
//  Created by Kylin on 16/5/1.
//  Copyright © 2016年 yanglinxia. All rights reserved.
// 考试攻略的tableViewCell  考规介绍/考前必读 等....

#import "YCExamStrategyCell.h"
#import "YCStrategyCell.h"
//#import "YCStratergyCellModel.h"

@interface YCExamStrategyCell()<UICollectionViewDataSource,UICollectionViewDelegate>
/**图片数组*/
@property(nonatomic,strong)NSMutableArray *imageArray;
/**标题数组*/
@property(nonatomic,strong)NSMutableArray *titleArray;
/**考试攻略cell*/
@property(nonatomic,strong)UICollectionView *strategyView;
/**布局*/
@property(nonatomic,strong)UICollectionViewFlowLayout *layout;
@end
static NSString *const strategyCell = @"strategyCell";
@implementation YCExamStrategyCell
+ (CGFloat)getCellHeight{
    return 93;
}

- (UICollectionView *)strategyView{
    
    if (!_strategyView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 0;
        layout.itemSize = CGSizeMake(kScreenWidth/ self.titleArray.count, 93);
        _strategyView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 93) collectionViewLayout:layout];
                _strategyView.dataSource = self;
        _strategyView.delegate = self;
        _strategyView.pagingEnabled = YES;
        _strategyView.backgroundColor = [UIColor whiteColor];
        _strategyView.showsHorizontalScrollIndicator = NO;
        _strategyView.showsVerticalScrollIndicator = NO;
        [_strategyView registerClass:[YCStrategyCell class] forCellWithReuseIdentifier:strategyCell];
        
    }
    
    return _strategyView;
}
- (NSMutableArray *)titleArray{
    if (!_titleArray) {
        _titleArray = [NSMutableArray arrayWithArray:@[@"考规介绍",@"考前必读",@"经验分享",@"考试秘笈"]];
    }
    
    return _titleArray;
}

- (NSMutableArray *)imageArray{
    if (!_imageArray) {
        _imageArray = [NSMutableArray arrayWithArray:@[@"考规介绍",@"考前必读",@"经验分享",@"考试秘笈"]];
    }
    
    return _imageArray;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor lightGrayColor];
        [self setupChildViews];
    }
    
    return self;
}

- (void)setupChildViews{
    [self.contentView addSubview:self.strategyView];
    
}

#pragma mark- collectionDataSource 方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    YCStrategyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:strategyCell forIndexPath:indexPath];
    cell.title = self.titleArray[indexPath.row];
    cell.image = self.imageArray[indexPath.row];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _titleArray.count ;
}


#pragma mark- collectionDelegate 方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    YCLog(@"%zd",indexPath.row);
    
    if ([_delegate respondsToSelector:@selector(YCStrategyCelldidSelectItemAtIndexPath:)]) {
        [self.delegate YCStrategyCelldidSelectItemAtIndexPath:indexPath];
    }
}

@end
